using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BardsTaleMapViewer {
  public class Game {
    public static byte [] _dumpAtari = Properties.Resources.Atari_dump.Extract (0);
    public static BitmapFont _bitmapFontSmall = new BitmapFont (Properties.Resources.Font4x6, 16, 4, 6, 1);
    public static BitmapFont _bitmapFont = new BitmapFont (Properties.Resources.AtariST_Fixed, 16, 8, 8, 1);

    public List<Dungeon> _dungeons;
    public Beastiary _beastiary;
    public Spellbook _spellbook;
    public Items _items;

    public Game () {
      _dungeons = new List<Dungeon> ();
      for (int i = 1; i <= 6; i++) {
        Dungeon dungeon = new Dungeon (i);
        _dungeons.Add (dungeon);
      }

      _beastiary = new Beastiary (this);
      _spellbook = new Spellbook (this);
      _items = new Items (this);

      _spellbook.Dump ();
      Console.WriteLine ();
      Console.WriteLine (_spellbook.DumpHtml ().ToString ());

      _beastiary.Dump ();
      Console.WriteLine ();
      Console.WriteLine (_beastiary.DumpHtml ().ToString ());

      _items.Dump ();
      Console.WriteLine ();
      Console.WriteLine (_items.DumpHtml ().ToString ());
      //MonsterType aa = new MonsterType (126, _beastiary);
      //string toto = aa.NamePlural;
    }

    public static int Lengthest (IEnumerable<string> strings) {
      int l = 0;
      foreach (string s in strings)
        if (s.Length > l)
          l = s.Length;
      return (l);
    }

    public static List<int> ReadArrayInt (int address, int addressCheck, int size) {
      List<int> array = new List<int> ();
      for (int i = 0; i < size; i++) {
        int value = Game._dumpAtari.ReadByte (ref address);
        array.Add (value);
      }
      if (address != addressCheck)
        throw new Exception ();
      return (array);
    }

    public static List<int> ReadArrayLong (int address, int addressCheck, int size) {
      List<int> array = new List<int> ();
      for (int i = 0; i < size; i++) {
        int value = (int) Game._dumpAtari.ReadLong (ref address);
        array.Add (value);
      }
      if (address != addressCheck)
        throw new Exception ();
      return (array);
    }

    public static List<string> ReadArrayString (int address, int addressCheck, int size, bool trim) {
      List<string> array = new List<string> ();
      for (int i = 0; i < size; i++) {
        int address2 = (int) Game._dumpAtari.ReadLong (ref address);
        string name;
        if (address2 == 0x00)
          name = "";
        else
          name = Game._dumpAtari.ReadString (address2);
        array.Add (trim ? name.Trim () : name);
      }
      if (address != addressCheck)
        throw new Exception ();
      return (array);
    }
  }
}
